#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

from persistance import *


class Backup:
  
  def __init__(self):
    self.mDB=ManageDB(Glob.dbName, Glob.user, Glob.passwd, Glob.host)
    logging.basicConfig(filename=Glob.LOG_FILENAME,level=logging.DEBUG)


  def userTable(self):
    if (self.mDB.executSQL(Glob.backup_user) == 0):
      logging.debug(u'Backup: userTable() SQL error : %s' % Glob.backup_user)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len(result) > 0:
        return result
      else:
        return 0


  def navTable(self):
    if (self.mDB.executSQL(Glob.backup_nav) == 0):
      logging.debug(u'Backup: navTable() SQL error : %s' % Glob.backup_nav)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len(result) > 0:
        return result
      else:
        return 0

    
  def pageTable(self):
    if (self.mDB.executSQL(Glob.backup_page) == 0):
      logging.debug(u'Backup: pageTable() SQL error : %s' % Glob.backup_page)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len(result) > 0:
        return result
      else:
        return 0   


  def configTable(self):
    if (self.mDB.executSQL(Glob.backup_config) == 0):
      logging.debug(u'Backup: configTable() SQL error : %s' % Glob.backup_config)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len(result) > 0:
        return result
      else:
        return 0


  def sessionTable(self):
    if (self.mDB.executSQL(Glob.backup_session) == 0):
      logging.debug(u'Backup: sessionTable() SQL error : %s' % Glob.backup_session)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len(result) > 0:
        return result
      else:
        return 0


  def saleTable(self):
    if (self.mDB.executSQL(Glob.backup_sale) == 0):
      logging.debug(u'Backup: saleTable() SQL error : %s' % Glob.backup_sale)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len(result) > 0:
        return result
      else:
        return 0


  def productTable(self):
    if (self.mDB.executSQL(Glob.backup_product) == 0):
      logging.debug(u'Backup: productTable() SQL error : %s' % Glob.backup_product)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len(result) > 0:
        return result
      else:
        return 0


  def helpTable(self):
    if (self.mDB.executSQL(Glob.backup_help) == 0):
      logging.debug(u'Backup: helpTable() SQL error : %s' % Glob.backup_help)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len(result) > 0:
        return result
      else:
        return 0
  
